|
|
|
|
|
|
|
For color images, the program can make separate counts for the pixels' red, green, and blue color components and draw three histograms. |
|
|
|
|
|
|
|
|
In Figure 6.5, example program Contrast has loaded a low-contrast picture. The three histograms show the number of pixels with red, green, and blue component values. All the color values that are used are bunched into a small part of the available horizontal space in the histograms. That means all of the pixels have similar color values and the image's contrast is low. If the colors were more evenly distributed, the histograms would have vertical bars across their entire ranges. |
|
|
|
|
|
|
|
|
The colors are also bunched into the left part of the histograms. That means the color components are relatively small, so the picture is dark. |
|
|
|
|
|
|
|
|
A program can adjust an image's contrast by changing the distribution of color values in these component histograms. It can use a function to map pixel component values into new values that are more evenly distributed. For example, it could multiply each value by a factor of 2 to spread the pixel values out and make them generally brighter. |
|
|
|
|
|
|
|
|
Example program Contrast does this. It examines the pixels in an image to build three color component histograms. It then examines each color's counts to find the largest and smallest. For example, the pixels may have red component values only between 50 and 100 instead of the entire possible range of 0 to 255. The program then adjusts the components so that their values are centered on the value 127. It also scales the components so that they occupy more of the space in the histograms. |
|
|
|
|
|
|
|
|
Figure 6.6 shows program Contrast stretching a low-contrast image's component values so that they span the range 0 to 256. It shows the new image and its component histograms. The new component values fill the histograms. |
|
|
|
|
|
|
|
|
Figure 6.5
Program Contrast displaying a low-contrast image with its color histograms. |
|
|
|
|
|